package SocialMediaSentiment;

import java.util.List;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import jxl.write.WriteException;

public class createSignificantCounter {
	
	public static void main(String[] args) throws WriteException, IOException
	{
		createSignificantWordFile("mediumCorrectedCounterTrainSetZero.xls", "mediumCorrectedCounterTrainSetZeroSignificant.xls" );
		createSignificantWordFile("mediumCorrectedCounterTrainSetNonZero.xls", "mediumCorrectedCounterTrainSetNonZeroSignificant.xls" );
	}
	
	public static void createSignificantWordFile(String oldfile, String newfile) throws IOException, WriteException
	{
		List<String> significantWords = getSignificantWords("mediumCorrectedCounterTrainSetAllSignificant.xls");
		HashMap<Integer, String[]> oldIndexWordsCount = ReadExcel
				.read(oldfile, 0, 1);
		Iterator<Integer> k = (Iterator<Integer>) oldIndexWordsCount.keySet().iterator();
		HashMap<String, String> toprint = new HashMap<String, String>();
		while(k.hasNext())
		{
			int index = k.next();
			String[] wordCount = oldIndexWordsCount.get(index);
			if(significantWords.contains(wordCount[0]))
			{
				toprint.put(wordCount[0], wordCount[1]);
			}
		}
		writeExcel.write(newfile, toprint);
		
	}

	public static List<String> getSignificantWords( String significantWordsFile ) throws IOException
	{
		HashMap<Integer, String[]> indexWordsCount = ReadExcel
				.read(significantWordsFile, 0, 1);
		Iterator<Integer> k = (Iterator<Integer>) indexWordsCount.keySet().iterator();
		List<String> significantWords = new ArrayList<String>();
		while(k.hasNext())
		{
			significantWords.add(indexWordsCount.get(k.next())[0]);
		}
		return significantWords;
	}
}
